<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
	<base href="<%=basePath%>">
	<title>更新用户注册邀请码</title>
	<script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
	<script src='<%=basePath%>dwrsystem/interface/unitService.js'></script>
	<script src='<%=basePath%>dwrsystem/engine.js'></script>
	<script src="<%=basePath%>js/validateJS.js"></script>
	<script src="<%=basePath%>js/tableForm.js"></script>
</head>

<body onload="bodyInit()"><div id="dataObj">
	<div id="displayDiv" class="formlayout" style="width:100%;height:100%;overflow: auto;">
		<form action="<%=basePath%>system-unit/UnitAction!userRegisterNumEdit.action" method="post" name="editForm">
			<input type="hidden" name="tuserregisternum.registerNumId" id="tuserregisternum.registerNumId" value="${userRegisterNumEdit.registerNumId }"/>
			<input type="hidden" name="tuserregisternum.unitId" id="tuserregisternum.unitId" value="${userRegisterNumEdit.unitId }"/>
			<input type="hidden" name="tuserregisternum.registerTimes" id="tuserregisternum.registerTimes" value="${userRegisterNumEdit.registerTimes }"/>
			<table id="editTable" class="inputTable">
				<tr>
					<th>用户注册邀请码 </th>
					<td >
					${userRegisterNumEdit.registerNum }
	<input type="hidden" name="editFormHidden"
	value="[{type:'input',id:'tuserregisternum.registerNum',name:'tuserregisternum.registerNum',value:'${userRegisterNumEdit.registerNum }',showText:'${userRegisterNumEdit.registerNum }',maxlength:'25',mustEnter:'yes'}]"/>
					
					</td>
				</tr>
				<tr>
					<th>可注册总次数</th>
					<td>
					${userRegisterNumEdit.registerTimesAll}
	<input type="hidden" name="editFormHidden"
		 value="[{type:'input',id:'tuserregisternum.registerTimesAll',name:'tuserregisternum.registerTimesAll',value:'${userRegisterNumEdit.registerTimesAll }',showText:'${userRegisterNumEdit.registerTimesAll }',maxlength:'15',mustEnter:'yes'}]"/>
	
					</td>
				</tr>
				<tr>   			
					<th>已经注册次数</th>
					<td>${empty userRegisterNumEdit.registerTimes ? 0 :userRegisterNumEdit.registerTimes }</td>
				</tr>
				<tr>
					<th>状态</th>
					<td>
					
	<c:if test="${userRegisterNumEdit.status == 1}">有效</c:if><c:if test="${userRegisterNumEdit.status == 0}">无效</c:if>
	<input type="hidden" name="editFormHidden"
		value="[{type:'select',id:'tuserregisternum.status',name:'tuserregisternum.status',value:'1&有效|0&无效',defaultSelect:'${userRegisterNumEdit.status }',
		showText:'<c:if test="${userRegisterNumEdit.status == 1}">有效</c:if><c:if test="${userRegisterNumEdit.status == 0}">无效</c:if>'}]"/>	
					</td>
				</tr>
				<tr>
					<th>备注</th>
					<td>
							${userRegisterNumEdit.note }
	<input type="hidden" name="editFormHidden"
							 value="[{type:'textarea',id:'tuserregisternum.note',name:'tuserregisternum.note',value:'${userRegisterNumEdit.note }',showText:'${userRegisterNumEdit.note }'}]"/>						
				
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="delDiv" style="display:none"><!-- 删除信息 -->
		<form action="<%=basePath%>system-unit/UnitAction!userRegisterNumDel.action" method="post" name="delForm">
			<input type="hidden" name="unitId" id="unitId" value="${userRegisterNumEdit.unitId }"/>
		</form>
	</div></div>
</body>

<script type="text/javascript">
var dhxLayout = createLayoutNormal('1C',false,true);

function bodyInit(){
	configLayout();
}

function configLayout(){
	var a = dhxLayout.cells('a');
	a.hideHeader();
	a.setText('主页面');
	a.fixSize(true, true);
	if(power.getPower() != '' && power.getPowerInsert() )
			createToolbarFromDHXLayoutCell(a,function(toolbar){
			    toolbar.addText("info", 1, "操作:");
			    toolbar.addSeparator("sep1", 2);
			    if(power.getPowerUpdate()){
			    	toolbar.addButton("update", 4, "修改", "settings.gif", "settings.gif");
			    	toolbar.addButton("forUpdate", 6, "提交", "save.gif", "save_dis.gif");
			    	toolbar.addButton("cancel", 7, "取消", "undo.gif", "undo_dis.gif");
			    	toolbar.hideItem('forUpdate');
			    	toolbar.hideItem('cancel');
			    }
	    		if(power.getPowerDelete())toolbar.addButton("delete", 8, "删除", "cut.gif", "cut_dis.gif");
			    toolbar.attachEvent("onClick", function(id) {
			    	if(id == 'delete'){
			    		validateDel();
			    	}
			    	if(id == 'update'){
			    		//updateUnit();
			    		tableForm.tableToForm();
			    		toolbar.showItem('forUpdate');
			    		toolbar.showItem('cancel');
			    		toolbar.hideItem('update');
			    		
			    	}
			    	if(id == 'cancel'){
			    		tableForm.formReturnTable();
			    		toolbar.hideItem('forUpdate');
			    		toolbar.hideItem('cancel');
			    		toolbar.showItem('update');
			    	}
			    	if(id == 'forUpdate'){
			    		validateEdit();
			    	}
			    });
			});
	a.attachObject('dataObj');
}

function addUserRegisterNumEdit(){
	layoutProgressOn(dhxLayout);
	document.location.href = '<%=basePath%>page/system/unit/userRegisterNum_add.jsp?unitId=' + '${userRegisterNumEdit.unitId }';
}

function validateEdit(){
	var rnum = document.getElementById('tuserregisternum.registerNum').value;
	if(trim(rnum)==''){parent.parent.parent.notifyWarn('请输入用户注册码');return;}
	if (!validatePattern.validateEnglish(rnum,false)){
		parent.parent.parent.notifyWarn('用户注册码非法，只能输入英文');
		return;
	}
	
	var rtimes = document.getElementById('tuserregisternum.registerTimesAll').value;
	if(trim(rtimes)==''){parent.parent.parent.notifyWarn('请输入可注册总次数');return;}
	if (!validatePattern.validateNumber(rtimes,false)){
		parent.parent.parent.notifyWarn('可注册总次数非法，只能输入数字');
		return;
	}

	layoutProgressOn(dhxLayout);
	unitService.hasTUnitUserRegisterNum({unitId:'${userRegisterNumEdit.unitId }', registerNum:rnum}, function(data){
		if(data == 1){
			parent.parent.parent.notifyWarn('已存在相同用户注册码');
			layoutProgressOff(dhxLayout);
			return;
		}else{
			document.forms["editForm"].submit();
		}
  	});
}

function validateDel(){
	var rtimes = document.getElementById('tuserregisternum.registerTimes').value;
	rtimes = (rtimes == '' || rtimes == 0) ? 0 : rtimes;
	confirmInfo('已有'+rtimes+'个用户使用此注册码，确认删除',
		function(choose){
			if('ok' == choose){
				layoutProgressOn(dhxLayout);
				document.forms["delForm"].submit();
			}else{
				return;
			}
		}
	);
}

</script>
</html>
